<?php

namespace app\http\Controllers\Manage;

use think\App;
use think\Request;
use app\models\common\OutApiAccessLogModel;

class OauthLogsController extends BaseController
{

    private $model;

    public function __construct(App $app, Request $request)
    {
        parent::__construct($app, $request);
        $this->model = new OutApiAccessLogModel();
    }

    /**
     * 列表页面
     * @param Request $request
     * @return void
     */
    public function index(Request $request)
    {
        $data = [];
        return $this->view('oauth_logs/list', $data);
    }


    /**
     * 获取列表数据
     * @param Request $request
     * @return void
     */
    public function getRecordList(Request $request)
    {
        $param = $request->param();
        $page = isset($param['page']) ? intval($param['page']) : 1;
        $limit = isset($param['limit']) ? intval($param['limit']) : 1;
        $count = $this->model->getRecordCount($param);
        $parger = turnPageToStartEnd($page, $limit);
        $list = $this->model->getRecordList($param, $parger['start'], $parger['limit']);
        return apiResponse(STATUS_CODE_SUCCESS, 'success', formatPager($count, $list, $page, $limit));
    }


    /**
     * 详情
     * @param $id
     * @param Request $request
     * @return void
     */
    public function detail($id, Request $request)
    {
        $data = $this->model->getInfoById($id);
        if (!$data) return $this->showErrorPage(STATUS_CODE_NOTFOUND, '数据不存在');
        return $this->view('oauth_logs/detail', $data);
    }
}